#pragma once
#include <iostream>
#include <pthread.h>
using namespace std;

// 封装锁
class Mutex
{
public:
    Mutex(pthread_mutex_t *mutex) : _mutex(mutex)
    {
    }
    ~Mutex()
    {
    }
    void lock()
    {
        pthread_mutex_lock(_mutex);
    }
    void unlock()
    {
        pthread_mutex_unlock(_mutex);
    }

private:
    pthread_mutex_t *_mutex;
};

class LockGuard
{
public:
    //构造
    LockGuard(pthread_mutex_t *mutex) : _mutex(mutex)
    {
        _mutex.lock();  //加锁
    }
    //析构
    ~LockGuard()
    {
        _mutex.unlock(); //解锁
    }
private:
    Mutex _mutex;
};
